/** 
 * ================================================================================
 * 		Project		: Kompas Bola
 * 		File		: TimeUtils.java
 * 		Description	: Time Utils
 * 		Called		: All
 * ================================================================================
 * */
package com.kompas.bola.application.utils;

import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.Locale;
import java.util.TimeZone;

import android.text.format.DateFormat;

public class TimeUtils {
	/** =========================================================================== */
	public static String getIndonesianDayName(int paramInt) {
		String str 					= "";
		String[] arrayOfString 		= new String[7];
		arrayOfString[0] 			= "Minggu";
		arrayOfString[1] 			= "Senin";
		arrayOfString[2] 			= "Selasa";
		arrayOfString[3] 			= "Maret";
		arrayOfString[4] 			= "Kamis";
		arrayOfString[5] 			= "Jumat";
		arrayOfString[6] 			= "Sabtu";
		
		if ((paramInt >= 0) && (paramInt < 7))
			str 					= arrayOfString[paramInt];
		return str;
	}
	/** =========================================================================== */
	public static String getIndonesianMonthName(int paramInt) {
		String str 					= "";
		String[] arrayOfString 		= new String[12];
		arrayOfString[0] 			= "Januari";
		arrayOfString[1] 			= "Febuari";
		arrayOfString[2] 			= "Maret";
		arrayOfString[3] 			= "April";
		arrayOfString[4] 			= "Mei";
		arrayOfString[5] 			= "Juni";
		arrayOfString[6] 			= "Juli";
		arrayOfString[7] 			= "Agustus";
		arrayOfString[8] 			= "September";
		arrayOfString[9] 			= "Oktober";
		arrayOfString[10] 			= "November";
		arrayOfString[11] 			= "Desember";
		
		if ((paramInt >= 0) && (paramInt < 13))
			str 					= arrayOfString[paramInt];
		return str;
	}
	/** =========================================================================== */
	public static String milisToTimeMessage(long paramLong) {
		StringBuilder build 		= new StringBuilder();
		int time 					= 0;
		int seconds 				= 0;
		int minute 					= 0;
		int day						= 0;

		Object obj1;
		Object obj2;

		if (paramLong >= 1000L)
			time 					= (int) (paramLong / 1000L);

		if (time >= 60)
			seconds 				= time / 60; // menit
		if (seconds >= 60)
			minute 					= seconds / 60; // jam
	    if (minute >= 24)
	    	day 					= minute / 24; // hari
	    
	    if(day <= 0){
			if (minute <= 0) {
				obj1 				= new StringBuilder(String.valueOf(seconds))
									.append(" menit");
				obj2 				= obj1 + "";
				build.append((String) obj2);
			} else {
				obj2 				= new StringBuilder(String.valueOf(minute))
									.append(" jam");
				obj1 				= obj2 + "";
				build.append((String) obj1);
			}	    	
	    }else{
    		obj2 					= new StringBuilder(String.valueOf(day))
	    							.append(" hari");
			obj1 					= obj2 + "";
			build.append((String) obj1);    	
	    }

		return (String) (build.toString() + " lalu");
	}
	/** =========================================================================== */
	public static String getTimestamp(String date){
		//2013-12-20 T17:30:34
		String getDateline			= (date != null ? date : Constants.EMPTY);
		
		StringBuilder build			= new StringBuilder();
		try {
			Object obj				= new Object();
			
			String year				= (getDateline.substring(0,4) + "-");	
			String month			= (getDateline.substring(4, 6) + "-");
			String day				= (getDateline.substring(6, 8) + " ");
			String hours			= (getDateline.substring(9, 11) + ":");
			String minutes			= (getDateline.substring(11, 13) + ":");
			String seconds			= (getDateline.substring(13, 15));
			
			String time				= year + month + day + hours + minutes + seconds;
	        
	        try {
				obj 				= new SimpleDateFormat("yyyy-MM-dd HH:mm:ss", Locale.US).parse((time).toString());
				build.append(new SimpleDateFormat("EEEEE, dd MMM yyyy", Locale.US).format(Long.valueOf(((Date)obj).getTime())));
				build.append(" | ");
				build.append(new SimpleDateFormat("HH:mm", Locale.US).format(Long.valueOf(((Date)obj).getTime())));
				build.append(" WIB");
			} catch (Exception e) {
				// TODO: handle exception
			}
		} catch (Exception e) {
			// TODO: handle exception
		}		
		return build.toString();		
	}
	/** =========================================================================== */
	public static String getTimestampComment(String date){
		//2013-12-20 T17:30:34
		String getDateline			= (date != null ? date : Constants.EMPTY);
		
		StringBuilder build			= new StringBuilder();
		try {
			Object obj				= new Object();
	        
	        try {
				obj 				= new SimpleDateFormat("yyyy-MM-dd HH:mm", Locale.US).parse((getDateline).toString());
				build.append(new SimpleDateFormat("EEEEE, dd MMM yyyy", Locale.US).format(Long.valueOf(((Date)obj).getTime())));
				build.append(" | ");
				build.append(new SimpleDateFormat("HH:mm", Locale.US).format(Long.valueOf(((Date)obj).getTime())));
				build.append(" WIB");
			} catch (Exception e) {
				// TODO: handle exception
			}
		} catch (Exception e) {
			// TODO: handle exception
		}		
		return build.toString();		
	}
	/** =========================================================================== */
	public static String showLongDateString(){
		String waktu 				= Constants.EMPTY;
	    Calendar c 					= Calendar.getInstance();
	    try {
			int hari				= c.get(Calendar.DAY_OF_WEEK)-1;
	    	int tgl					= c.get(Calendar.DATE);
			int bulan				= c.get(Calendar.MONTH);
			int tahun				= c.get(Calendar.YEAR);
			
			int jam					= c.get(Calendar.HOUR_OF_DAY);
			int menit				= c.get(Calendar.MINUTE);
						
			try {
				waktu				= getIndonesianDayName(hari) + ", " 
									+ tgl + " " 
									+ getIndonesianMonthName(bulan) + " "
									+ tahun + " | "
									+ jam + ":"
									+ menit + " " ;
			} catch (Exception e) {}
		} catch (Exception e) {
			// TODO: handle exception
		}
		return waktu + " WIB";
	}
	/** =========================================================================== */
}
